<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - cuda_dlib.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2015  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_DNN_CuDA_H_
<font color='#0000FF'>#define</font> DLIB_DNN_CuDA_H_


<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='tensor.h.html'>tensor.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../geometry/rectangle.h.html'>../geometry/rectangle.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../dnn/utilities.h.html'>../dnn/utilities.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>
    <font color='#0000FF'>namespace</font> cuda 
    <b>{</b>

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_device'></a>set_device</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>int</u></font> dev
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>int</u></font> <b><a name='get_device'></a>get_device</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>int</u></font> <b><a name='get_num_devices'></a>get_num_devices</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        std::string <b><a name='get_device_name'></a>get_device_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>int</u></font> device
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_current_device_blocking_sync'></a>set_current_device_blocking_sync</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='can_access_peer'></a>can_access_peer</b> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> device_id, <font color='#0000FF'><u>int</u></font> peer_device_id<font face='Lucida Console'>)</font>;
        <font color='#0000FF'><u>bool</u></font> <b><a name='can_access_peer'></a>can_access_peer</b> <font face='Lucida Console'>(</font><font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> device, <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> peer_device<font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='device_synchronize'></a>device_synchronize</b> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> dev<font face='Lucida Console'>)</font>;
        <font color='#0000FF'><u>void</u></font> <b><a name='device_synchronize'></a>device_synchronize</b> <font face='Lucida Console'>(</font><font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> dev<font face='Lucida Console'>)</font>;


        <font color='#0000FF'>class</font> <b><a name='raii_set_device'></a>raii_set_device</b>
        <b>{</b>
        <font color='#0000FF'>public</font>:
            <b><a name='raii_set_device'></a>raii_set_device</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>delete</font>;
            <b><a name='raii_set_device'></a>raii_set_device</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> raii_set_device<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>delete</font>;
            raii_set_device<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> raii_set_device<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>delete</font>;

            <b><a name='raii_set_device'></a>raii_set_device</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> dev<font face='Lucida Console'>)</font>
            <b>{</b>
                prev_dev <font color='#5555FF'>=</font> <font color='#BB00BB'>get_device</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>set_device</font><font face='Lucida Console'>(</font>dev<font face='Lucida Console'>)</font>;
            <b>}</b>

            <b><a name='raii_set_device'></a>raii_set_device</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> dev<font face='Lucida Console'>)</font>
            <b>{</b>
                prev_dev <font color='#5555FF'>=</font> <font color='#BB00BB'>get_device</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>set_device</font><font face='Lucida Console'>(</font>dev.<font color='#BB00BB'>device_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'><u>void</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> dev<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>set_device</font><font face='Lucida Console'>(</font>dev<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'><u>void</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> dev<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>set_device</font><font face='Lucida Console'>(</font>dev.<font color='#BB00BB'>device_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            ~<b><a name='raii_set_device'></a>raii_set_device</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <b><a name='noexcept'></a>noexcept</b><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>set_device</font><font face='Lucida Console'>(</font>prev_dev<font face='Lucida Console'>)</font>;
            <b>}</b>

        <font color='#0000FF'>private</font>:
            <font color='#0000FF'><u>int</u></font> prev_dev;
        <b>}</b>;


<font color='#0000FF'>#ifdef</font> DLIB_USE_CUDA

        <font color='#0000FF'>class</font> <b><a name='enable_peer_access'></a>enable_peer_access</b>
        <b>{</b>
        <font color='#0000FF'>public</font>:

            <b><a name='enable_peer_access'></a>enable_peer_access</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>delete</font>;
            <b><a name='enable_peer_access'></a>enable_peer_access</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> enable_peer_access<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>delete</font>;
            enable_peer_access<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> enable_peer_access<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>delete</font>;

            <b><a name='enable_peer_access'></a>enable_peer_access</b><font face='Lucida Console'>(</font>
                <font color='#0000FF'><u>int</u></font> device_id,
                <font color='#0000FF'><u>int</u></font> peer_device_id
            <font face='Lucida Console'>)</font>;

            <b><a name='enable_peer_access'></a>enable_peer_access</b><font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> device,
                <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> peer_device
            <font face='Lucida Console'>)</font> : enable_peer_access<font face='Lucida Console'>(</font>device.device_id<font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, peer_device.device_id<font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b><b>}</b>

            ~<b><a name='enable_peer_access'></a>enable_peer_access</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <b><a name='noexcept'></a>noexcept</b><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'><u>bool</u></font> call_disable;
            <font color='#0000FF'><u>int</u></font> device_id;
            <font color='#0000FF'><u>int</u></font> peer_device_id;
        <b>}</b>;

    <font color='#009900'>// -----------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='inverse_norms'></a>inverse_norms</b> <font face='Lucida Console'>(</font>
            resizable_tensor<font color='#5555FF'>&amp;</font> invnorms,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> data,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> eps
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='dot_prods'></a>dot_prods</b> <font face='Lucida Console'>(</font>
            resizable_tensor<font color='#5555FF'>&amp;</font> out,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> lhs,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> rhs
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='dot_prods'></a>dot_prods</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>bool</u></font> add_to,
            tensor<font color='#5555FF'>&amp;</font> out,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> lhs,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> rhs
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='scale_columns'></a>scale_columns</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> out,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> m,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> v
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='scale_rows'></a>scale_rows</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> out,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> m,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> v
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='scale_rows2'></a>scale_rows2</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>float</u></font> beta, 
            tensor<font color='#5555FF'>&amp;</font> out,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> m1,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> m2,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> v1,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> v2
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='exp'></a>exp</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='log'></a>log</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='log10'></a>log10</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_tensor'></a>set_tensor</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> t,
            <font color='#0000FF'><u>float</u></font> value
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='scale_tensor'></a>scale_tensor</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> t,
            <font color='#0000FF'><u>float</u></font> value
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='multiply'></a>multiply</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>bool</u></font> add_to,
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src1,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src2
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='multiply_conv'></a>multiply_conv</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>bool</u></font> add_to,
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src1,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src2
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='multiply_zero_padded'></a>multiply_zero_padded</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>bool</u></font> add_to,
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src1,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src2
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='scale_channels'></a>scale_channels</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>bool</u></font> add_to,
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> scales
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add'></a>add</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src1,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src2
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// -----------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='affine_transform'></a>affine_transform</b><font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> A,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> B
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='affine_transform'></a>affine_transform</b><font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> A
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='affine_transform'></a>affine_transform</b><font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src1,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src2,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> A,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> B,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> C
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='affine_transform'></a>affine_transform</b><font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src1,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src2,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> A,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> B
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='affine_transform'></a>affine_transform</b><font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src1,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src2,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src3,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> A,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> B,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> C,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> D
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='affine_transform_range'></a>affine_transform_range</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>size_t</u></font> begin,
            <font color='#0000FF'><u>size_t</u></font> end,
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src1,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src2,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src3,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> A,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> B,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> C
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='affine_transform'></a>affine_transform</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
            tensor<font color='#5555FF'>&amp;</font> dest, 
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src1, 
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src2, 
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src3, 
            <font color='#0000FF'><u>float</u></font> A, 
            <font color='#0000FF'><u>float</u></font> B,
            <font color='#0000FF'><u>float</u></font> C
        <font face='Lucida Console'>)</font>;

        <font color='#009900'>// Note that this function isn't in the tt:: namespace because add_scaled() is
</font>        <font color='#009900'>// called by cuda::add() so we don't need a tt:: version of add_scaled().  
</font>        <font color='#0000FF'><u>void</u></font> <b><a name='add_scaled'></a>add_scaled</b><font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> scale,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add_cv_to_all_columns'></a>add_cv_to_all_columns</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>float</u></font> beta, 
            tensor<font color='#5555FF'>&amp;</font> dest, 
            <font color='#0000FF'><u>float</u></font> alpha, 
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// -----------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='affine_transform'></a>affine_transform</b><font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> A,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> B
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// -----------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='affine_transform_conv'></a>affine_transform_conv</b><font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> A,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> B
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='compute_adam_update'></a>compute_adam_update</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>size_t</u></font> begin,
            <font color='#0000FF'><u>size_t</u></font> end,
            tensor<font color='#5555FF'>&amp;</font> s,
            tensor<font color='#5555FF'>&amp;</font> m,
            tensor<font color='#5555FF'>&amp;</font> v,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> t,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> learning_rate,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> weight_decay,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> momentum1,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> momentum2,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> params,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> params_grad
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// -----------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='assign_bias_gradient'></a>assign_bias_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// -----------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='layer_normalize'></a>layer_normalize</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> eps,
            resizable_tensor<font color='#5555FF'>&amp;</font> dest,
            resizable_tensor<font color='#5555FF'>&amp;</font> means,
            resizable_tensor<font color='#5555FF'>&amp;</font> invstds,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gamma,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> beta
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='layer_normalize_gradient'></a>layer_normalize_gradient</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> eps,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> means,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> invstds,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gamma,
            tensor<font color='#5555FF'>&amp;</font> src_grad,
            tensor<font color='#5555FF'>&amp;</font> gamma_grad,
            tensor<font color='#5555FF'>&amp;</font> beta_grad
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// -----------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='threshold'></a>threshold</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> data,
            <font color='#0000FF'><u>float</u></font> thresh
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='dot'></a>dot</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> a,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> b,
            tensor<font color='#5555FF'>&amp;</font> result,
            <font color='#0000FF'><u>size_t</u></font> idx
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='prelu'></a>prelu</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> param
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='prelu_gradient'></a>prelu_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> param,
            tensor<font color='#5555FF'>&amp;</font> params_grad 
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='leaky_relu'></a>leaky_relu</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> alpha
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='leaky_relu_gradient'></a>leaky_relu_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> alpha
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='mish'></a>mish</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='mish_gradient'></a>mish_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='clipped_relu'></a>clipped_relu</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> coef
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='clipped_relu_gradient'></a>clipped_relu_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> ceiling
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='elu'></a>elu</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> alpha
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='elu_gradient'></a>elu_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> alpha
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='gelu'></a>gelu</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='gelu_gradient'></a>gelu_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='smelu'></a>smelu</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> beta
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='smelu_gradient'></a>smelu_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> beta
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='silu'></a>silu</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='silu_gradient'></a>silu_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='resize_bilinear'></a>resize_bilinear</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'><u>long</u></font> <font color='#0000FF'><u>long</u></font> dest_row_stride,
            <font color='#0000FF'><u>long</u></font> <font color='#0000FF'><u>long</u></font> dest_channel_stride,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'><u>long</u></font> <font color='#0000FF'><u>long</u></font> src_row_stride,
            <font color='#0000FF'><u>long</u></font> <font color='#0000FF'><u>long</u></font> src_channel_stride
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='resize_bilinear_gradient'></a>resize_bilinear_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'><u>long</u></font> <font color='#0000FF'><u>long</u></font> grad_row_stride,
            <font color='#0000FF'><u>long</u></font> <font color='#0000FF'><u>long</u></font> grad_channel_stride,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input,
            <font color='#0000FF'><u>long</u></font> <font color='#0000FF'><u>long</u></font> gradient_input_row_stride,
            <font color='#0000FF'><u>long</u></font> <font color='#0000FF'><u>long</u></font> gradient_input_channel_stride
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='resize_bilinear'></a>resize_bilinear</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src
        <font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>resize_bilinear</font><font face='Lucida Console'>(</font>dest, dest.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, dest.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>dest.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, src, src.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, src.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>src.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='resize_bilinear_gradient'></a>resize_bilinear_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input
        <font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>resize_bilinear_gradient</font><font face='Lucida Console'>(</font>grad, grad.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, grad.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>grad.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, gradient_input, gradient_input.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, gradient_input.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>gradient_input.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='reorg'></a>reorg</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> row_stride,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> col_stride,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='reorg_gradient'></a>reorg_gradient</b> <font face='Lucida Console'>(</font>
            tensor<font color='#5555FF'>&amp;</font> grad,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> row_stride,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> col_stride,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> gradient_input
        <font face='Lucida Console'>)</font>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='copy_tensor'></a>copy_tensor</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>bool</u></font> add_to,
            tensor<font color='#5555FF'>&amp;</font> dest,
            <font color='#0000FF'><u>size_t</u></font> dest_k_offset,
            <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> src,
            <font color='#0000FF'><u>size_t</u></font> src_k_offset,
            <font color='#0000FF'><u>size_t</u></font> count_k
        <font face='Lucida Console'>)</font>;


    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'>class</font> <b><a name='compute_loss_binary_log_per_pixel'></a>compute_loss_binary_log_per_pixel</b>
        <b>{</b>
            <font color='#009900'>/*!
                The point of this class is to compute the loss computed by
                loss_binary_log_per_pixel_, but to do so with CUDA.
            !*/</font>
        <font color='#0000FF'>public</font>:

            <b><a name='compute_loss_binary_log_per_pixel'></a>compute_loss_binary_log_per_pixel</b><font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>
            <b>{</b>
            <b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
                <font color='#0000FF'>typename</font> const_label_iterator
                <font color='#5555FF'>&gt;</font>
            <font color='#0000FF'><u>void</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
                const_label_iterator truth,
                <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> subnetwork_output,
                tensor<font color='#5555FF'>&amp;</font> gradient,
                <font color='#0000FF'><u>double</u></font><font color='#5555FF'>&amp;</font> loss
            <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> image_size <font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>subnetwork_output.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>size_t</u></font> bytes_per_plane <font color='#5555FF'>=</font> image_size<font color='#5555FF'>*</font><font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font>;
                <font color='#009900'>// Allocate a cuda buffer to store all the truth images and also one float
</font>                <font color='#009900'>// for the scalar loss output.
</font>                buf <font color='#5555FF'>=</font> <font color='#BB00BB'>device_global_buffer</font><font face='Lucida Console'>(</font>subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>bytes_per_plane <font color='#5555FF'>+</font> <font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> loss_buf <font color='#5555FF'>=</font> static_pointer_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>buf, <font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                buf <font color='#5555FF'>=</font> buf<font color='#5555FF'>+</font><font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font>;

                <font color='#009900'>// copy the truth data into a cuda buffer.
</font>                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i, <font color='#5555FF'>+</font><font color='#5555FF'>+</font>truth<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> t <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>truth;
                    <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>t.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>t.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>memcpy</font><font face='Lucida Console'>(</font>buf <font color='#5555FF'>+</font> i<font color='#5555FF'>*</font>bytes_per_plane, <font color='#5555FF'>&amp;</font><font color='#BB00BB'>t</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, bytes_per_plane<font face='Lucida Console'>)</font>;
                <b>}</b>

                <font color='#0000FF'>auto</font> truth_buf <font color='#5555FF'>=</font> static_pointer_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>buf, subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>image_size<font face='Lucida Console'>)</font>;

                <font color='#BB00BB'>do_work</font><font face='Lucida Console'>(</font>loss_buf, truth_buf, subnetwork_output, gradient, loss<font face='Lucida Console'>)</font>;
            <b>}</b>

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'>static</font> <font color='#0000FF'><u>void</u></font> <b><a name='do_work'></a>do_work</b><font face='Lucida Console'>(</font>
                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> loss_work_buffer,
                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> truth_buffer,
                <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> subnetwork_output,
                tensor<font color='#5555FF'>&amp;</font> gradient,
                <font color='#0000FF'><u>double</u></font><font color='#5555FF'>&amp;</font> loss
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'>mutable</font> cuda_data_void_ptr buf;
        <b>}</b>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'>class</font> <b><a name='compute_loss_multiclass_log_per_pixel'></a>compute_loss_multiclass_log_per_pixel</b>
        <b>{</b>
            <font color='#009900'>/*!
                The point of this class is to compute the loss computed by
                loss_multiclass_log_per_pixel_, but to do so with CUDA.
            !*/</font>
        <font color='#0000FF'>public</font>:

            <b><a name='compute_loss_multiclass_log_per_pixel'></a>compute_loss_multiclass_log_per_pixel</b><font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>
            <b>{</b>
            <b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
                <font color='#0000FF'>typename</font> const_label_iterator
                <font color='#5555FF'>&gt;</font>
            <font color='#0000FF'><u>void</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
                const_label_iterator truth,
                <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> subnetwork_output,
                tensor<font color='#5555FF'>&amp;</font> gradient,
                <font color='#0000FF'><u>double</u></font><font color='#5555FF'>&amp;</font> loss
            <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> image_size <font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>subnetwork_output.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>size_t</u></font> bytes_per_plane <font color='#5555FF'>=</font> image_size<font color='#5555FF'>*</font><font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font>uint16_t<font face='Lucida Console'>)</font>;
                <font color='#009900'>// Allocate a cuda buffer to store all the truth images and also one float
</font>                <font color='#009900'>// for the scalar loss output.
</font>                buf <font color='#5555FF'>=</font> <font color='#BB00BB'>device_global_buffer</font><font face='Lucida Console'>(</font>subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>bytes_per_plane <font color='#5555FF'>+</font> <font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> loss_buf <font color='#5555FF'>=</font> static_pointer_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>buf, <font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                buf <font color='#5555FF'>=</font> buf<font color='#5555FF'>+</font><font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font>;

                <font color='#009900'>// copy the truth data into a cuda buffer.
</font>                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i, <font color='#5555FF'>+</font><font color='#5555FF'>+</font>truth<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font>uint16_t<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> t <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>truth;
                    <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>t.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>t.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>memcpy</font><font face='Lucida Console'>(</font>buf <font color='#5555FF'>+</font> i<font color='#5555FF'>*</font>bytes_per_plane, <font color='#5555FF'>&amp;</font><font color='#BB00BB'>t</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, bytes_per_plane<font face='Lucida Console'>)</font>;
                <b>}</b>

                <font color='#0000FF'>auto</font> truth_buf <font color='#5555FF'>=</font> static_pointer_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> uint16_t<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>buf, subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>image_size<font face='Lucida Console'>)</font>;

                <font color='#BB00BB'>do_work</font><font face='Lucida Console'>(</font>loss_buf, truth_buf, subnetwork_output, gradient, loss<font face='Lucida Console'>)</font>;
            <b>}</b>

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'>static</font> <font color='#0000FF'><u>void</u></font> <b><a name='do_work'></a>do_work</b><font face='Lucida Console'>(</font>
                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> loss_work_buffer,
                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> uint16_t<font color='#5555FF'>&gt;</font> truth_buffer,
                <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> subnetwork_output,
                tensor<font color='#5555FF'>&amp;</font> gradient,
                <font color='#0000FF'><u>double</u></font><font color='#5555FF'>&amp;</font> loss
            <font face='Lucida Console'>)</font>;
            
            <font color='#0000FF'>mutable</font> cuda_data_void_ptr buf;
        <b>}</b>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'>class</font> <b><a name='compute_loss_multiclass_log_per_pixel_weighted'></a>compute_loss_multiclass_log_per_pixel_weighted</b>
        <b>{</b>
            <font color='#009900'>/*!
                The point of this class is to compute the loss computed by
                loss_multiclass_log_per_pixel_weighted_, but to do so with CUDA.
            !*/</font>
        <font color='#0000FF'>public</font>:

            <b><a name='compute_loss_multiclass_log_per_pixel_weighted'></a>compute_loss_multiclass_log_per_pixel_weighted</b><font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>
            <b>{</b>
            <b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
                <font color='#0000FF'>typename</font> const_label_iterator
                <font color='#5555FF'>&gt;</font>
            <font color='#0000FF'><u>void</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
                const_label_iterator truth,
                <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> subnetwork_output,
                tensor<font color='#5555FF'>&amp;</font> gradient,
                <font color='#0000FF'><u>double</u></font><font color='#5555FF'>&amp;</font> loss
            <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> image_size <font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>subnetwork_output.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>size_t</u></font> bytes_per_plane <font color='#5555FF'>=</font> image_size<font color='#5555FF'>*</font><font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font>uint16_t<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>size_t</u></font> weight_bytes_per_plane <font color='#5555FF'>=</font> image_size<font color='#5555FF'>*</font><font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font>;
                matrix<font color='#5555FF'>&lt;</font>uint16_t<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>labels</font><font face='Lucida Console'>(</font>truth<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, truth<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>weights</font><font face='Lucida Console'>(</font>truth<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, truth<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#009900'>// Allocate a cuda buffer to store all the truth images and also one float
</font>                <font color='#009900'>// for the scalar loss output.
</font>                buf <font color='#5555FF'>=</font> <font color='#BB00BB'>device_global_buffer</font><font face='Lucida Console'>(</font>subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>bytes_per_plane <font color='#5555FF'>+</font> weight_bytes_per_plane<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> loss_buf <font color='#5555FF'>=</font> static_pointer_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>buf, <font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                buf <font color='#5555FF'>=</font> buf<font color='#5555FF'>+</font><font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> weights_offset <font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> bytes_per_plane;
                <font color='#009900'>// copy the truth data into a cuda buffer.
</font>                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i, <font color='#5555FF'>+</font><font color='#5555FF'>+</font>truth<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font>weighted_label<font color='#5555FF'>&lt;</font>uint16_t<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> t <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>truth;
                    <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>t.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>t.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> t.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>; c <font color='#5555FF'>&lt;</font> t.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
                        <b>{</b>
                            <font color='#BB00BB'>labels</font><font face='Lucida Console'>(</font>r, c<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>t</font><font face='Lucida Console'>(</font>r, c<font face='Lucida Console'>)</font>.label;
                            <font color='#BB00BB'>weights</font><font face='Lucida Console'>(</font>r, c<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>t</font><font face='Lucida Console'>(</font>r, c<font face='Lucida Console'>)</font>.weight;
                        <b>}</b>
                    <b>}</b>
                    <font color='#BB00BB'>memcpy</font><font face='Lucida Console'>(</font>buf <font color='#5555FF'>+</font> i<font color='#5555FF'>*</font>bytes_per_plane, <font color='#5555FF'>&amp;</font><font color='#BB00BB'>labels</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, bytes_per_plane<font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>memcpy</font><font face='Lucida Console'>(</font>buf <font color='#5555FF'>+</font> weights_offset <font color='#5555FF'>+</font> i<font color='#5555FF'>*</font>weight_bytes_per_plane, <font color='#5555FF'>&amp;</font><font color='#BB00BB'>weights</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>, <font color='#979000'>0</font><font face='Lucida Console'>)</font>, weight_bytes_per_plane<font face='Lucida Console'>)</font>;
                <b>}</b>

                <font color='#0000FF'>auto</font> truth_buf <font color='#5555FF'>=</font> static_pointer_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> uint16_t<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>buf, subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>image_size<font face='Lucida Console'>)</font>;
                buf <font color='#5555FF'>=</font> buf<font color='#5555FF'>+</font>weights_offset;
                <font color='#0000FF'>auto</font> weights_buf <font color='#5555FF'>=</font> static_pointer_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>buf, subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>image_size<font face='Lucida Console'>)</font>;

                <font color='#BB00BB'>do_work</font><font face='Lucida Console'>(</font>loss_buf, truth_buf, weights_buf, subnetwork_output, gradient, loss<font face='Lucida Console'>)</font>;
            <b>}</b>

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'>static</font> <font color='#0000FF'><u>void</u></font> <b><a name='do_work'></a>do_work</b><font face='Lucida Console'>(</font>
                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> loss_work_buffer,
                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> uint16_t<font color='#5555FF'>&gt;</font> truth_buffer,
                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> weights_buffer,
                <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> subnetwork_output,
                tensor<font color='#5555FF'>&amp;</font> gradient,
                <font color='#0000FF'><u>double</u></font><font color='#5555FF'>&amp;</font> loss
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'>mutable</font> cuda_data_void_ptr buf;
        <b>}</b>;

    <font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'>class</font> <b><a name='compute_loss_mean_squared_per_channel_and_pixel'></a>compute_loss_mean_squared_per_channel_and_pixel</b>
        <b>{</b>
            <font color='#009900'>/*!
                The point of this class is to compute the loss computed by
                loss_mean_squared_per_channel_and_pixel_, but to do so with CUDA.
            !*/</font>
        <font color='#0000FF'>public</font>:

            <b><a name='compute_loss_mean_squared_per_channel_and_pixel'></a>compute_loss_mean_squared_per_channel_and_pixel</b><font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>
            <b>{</b>
            <b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
                <font color='#0000FF'>typename</font> const_label_iterator
                <font color='#5555FF'>&gt;</font>
            <font color='#0000FF'><u>void</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
                const_label_iterator truth,
                <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> subnetwork_output,
                tensor<font color='#5555FF'>&amp;</font> gradient,
                <font color='#0000FF'><u>double</u></font><font color='#5555FF'>&amp;</font> loss
            <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> image_size <font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>subnetwork_output.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>subnetwork_output.<font color='#BB00BB'>k</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>size_t</u></font> bytes_per_image <font color='#5555FF'>=</font> image_size<font color='#5555FF'>*</font><font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font>;
                <font color='#009900'>// Allocate a cuda buffer to store all the truth images and also one float
</font>                <font color='#009900'>// for the scalar loss output.
</font>                buf <font color='#5555FF'>=</font> <font color='#BB00BB'>device_global_buffer</font><font face='Lucida Console'>(</font>subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>bytes_per_image <font color='#5555FF'>+</font> <font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> loss_buf <font color='#5555FF'>=</font> static_pointer_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>buf, <font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                buf <font color='#5555FF'>=</font> buf<font color='#5555FF'>+</font><font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font>;

                <font color='#0000FF'>const</font> <font color='#0000FF'><u>size_t</u></font> bytes_per_plane <font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>subnetwork_output.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>float</u></font><font face='Lucida Console'>)</font>;

                <font color='#009900'>// copy the truth data into a cuda buffer.
</font>                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i, <font color='#5555FF'>+</font><font color='#5555FF'>+</font>truth<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>const</font> <font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font> t <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>truth;
                    <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>t.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>k</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>size_t</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> t.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> <b>{</b>
                        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>t[j].<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>t[j].<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> subnetwork_output.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        <font color='#BB00BB'>memcpy</font><font face='Lucida Console'>(</font>buf <font color='#5555FF'>+</font> i<font color='#5555FF'>*</font>bytes_per_image <font color='#5555FF'>+</font> j<font color='#5555FF'>*</font>bytes_per_plane, <font color='#5555FF'>&amp;</font>t[j]<font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, bytes_per_plane<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>

                <font color='#0000FF'>auto</font> truth_buf <font color='#5555FF'>=</font> static_pointer_cast<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>buf, subnetwork_output.<font color='#BB00BB'>num_samples</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>image_size<font face='Lucida Console'>)</font>;

                <font color='#BB00BB'>do_work</font><font face='Lucida Console'>(</font>loss_buf, truth_buf, subnetwork_output, gradient, loss<font face='Lucida Console'>)</font>;
            <b>}</b>

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'>static</font> <font color='#0000FF'><u>void</u></font> <b><a name='do_work'></a>do_work</b><font face='Lucida Console'>(</font>
                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> loss_work_buffer,
                cuda_data_ptr<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font> truth_buffer,
                <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> subnetwork_output,
                tensor<font color='#5555FF'>&amp;</font> gradient,
                <font color='#0000FF'><u>double</u></font><font color='#5555FF'>&amp;</font> loss
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'>mutable</font> cuda_data_void_ptr buf;
        <b>}</b>;

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>#else</font> <font color='#009900'>// if DLIB_USE_CUDA NOT DEFINED
</font>
        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='set_device'></a>set_device</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>int</u></font> id
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>id <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>, "<font color='#CC0000'>dlib::cuda::set_device(id) called with an invalid device id.</font>"<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>int</u></font> <b><a name='get_device'></a>get_device</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font><b>{</b> <font color='#0000FF'>return</font> <font color='#979000'>0</font>; <b>}</b>

        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>int</u></font> <b><a name='get_num_devices'></a>get_num_devices</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#979000'>1</font>; <b>}</b>

        <font color='#0000FF'>inline</font> std::string <b><a name='get_device_name'></a>get_device_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>int</u></font> device
        <font face='Lucida Console'>)</font> 
        <b>{</b>
            <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>device <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>, "<font color='#CC0000'>dlib::cuda::set_device(id) called with an invalid device id.</font>"<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> "<font color='#CC0000'>CUDA_DISABLED</font>";
        <b>}</b>

        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='set_current_device_blocking_sync'></a>set_current_device_blocking_sync</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <b>{</b><b>}</b>


        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>bool</u></font> <b><a name='can_access_peer'></a>can_access_peer</b> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> , <font color='#0000FF'><u>int</u></font> <font face='Lucida Console'>)</font>
        <b>{</b> <font color='#0000FF'>return</font> <font color='#979000'>false</font>; <b>}</b>
        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>bool</u></font> <b><a name='can_access_peer'></a>can_access_peer</b> <font face='Lucida Console'>(</font><font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> , <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> <font face='Lucida Console'>)</font>
        <b>{</b> <font color='#0000FF'>return</font> <font color='#979000'>false</font>; <b>}</b>

        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='device_synchronize'></a>device_synchronize</b> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> <font face='Lucida Console'>)</font><b>{</b><b>}</b>
        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='device_synchronize'></a>device_synchronize</b> <font face='Lucida Console'>(</font><font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> <font face='Lucida Console'>)</font><b>{</b><b>}</b>

        <font color='#0000FF'>class</font> <b><a name='enable_peer_access'></a>enable_peer_access</b>
        <b>{</b>
        <font color='#0000FF'>public</font>:
            <b><a name='enable_peer_access'></a>enable_peer_access</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>delete</font>;
            <b><a name='enable_peer_access'></a>enable_peer_access</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> enable_peer_access<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>delete</font>;
            enable_peer_access<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> enable_peer_access<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>delete</font>;
            <b><a name='enable_peer_access'></a>enable_peer_access</b><font face='Lucida Console'>(</font> <font color='#0000FF'><u>int</u></font>, <font color='#0000FF'><u>int</u></font> <font face='Lucida Console'>)</font><b>{</b><b>}</b>
            <b><a name='enable_peer_access'></a>enable_peer_access</b><font face='Lucida Console'>(</font> <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font>, <font color='#0000FF'>const</font> tensor<font color='#5555FF'>&amp;</font> <font face='Lucida Console'>)</font> <b>{</b><b>}</b>
        <b>}</b>;

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_USE_CUDA
</font>
    <b>}</b> 
<b>}</b>


<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_DNN_CuDA_H_
</font>

</pre></body></html>